/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import model.dao.util.MySqlDataAccessHelper;
import model.pojo.ProductDetail;

/**
 *
 * @author Ti Oc
 */
public class ProductDetailDAO 
{
    public static ProductDetail getProductDetail(int idProduct)
    {
        ProductDetail pddt = new ProductDetail();
        String sql = String.format("SELECT pddt.idProductDetail, pd.nameProduct, mp.detailMicroProcessor, mpc.detailMicroProcessorCache, c.detailCpu, r.detailRam, gp.detailGraphic, h.detailHdd, hd.detailHardDisk, ig.detailIntergrated,dp.detailDisplay, nw.detailNetwork, wl.detailWireless, kb.detailKeyboard, ptd.detailPointingDevice,ep.detailExternalPort, os.detailOperatingSystem, bt.detailBattery "
                + "FROM Product As pd, ProductDetail As pddt, MicroProcessor As mp, MicroProcessorCache As mpc, Cpu As c, Ram As r, Graphic As gp, Hdd As h, HardDisk As hd, Intergrated As ig, Display As dp, Network As nw, Wireless As wl, Keyboard As kb, PointingDevice As ptd, ExternalPorts As ep, OperatingSystem As os, Battery As bt "
                + "WHERE pd.idProduct = pddt.idProduct And pddt.idMicroProcessor = mp.idMicroProcessor And pddt.idMicroProcessorCache = mpc.idMicroProcessorCache And pddt.idCpu = c.idCpu And pddt.idRam = r.idRam And pddt.idGraphic = gp.idGraphic And pddt.idHdd = h.idHdd And pddt.idHardDisk = hd.idHardDisk And pddt.idIntegrated = ig.idIntergrated And pddt.idDisplay = dp.idDisplay And pddt.idNetwork = nw.idNetwork And pddt.idWireless = wl.idWireless And pddt.idKeyboard = kb.idKeyboard And pddt.idPointingDevice = ptd.idPointingDevice And pddt.idExternalPort = ep.idExternalPort And pddt.idOperatingSystem = os.idOperatingSystem And pddt.idBattery = bt.idBattery And pddt.idProduct = %d", idProduct);
        MySqlDataAccessHelper helper = new MySqlDataAccessHelper();
        helper.open();
        ResultSet rs = helper.executeQuery(sql); 
        try
        {
            while(rs.next())
            {
                pddt.setIdProductDetail(rs.getInt("idProductDetail"));
                pddt.setNameProduct(rs.getString("nameProduct"));
                pddt.setDetailMicroProcessor(rs.getString("detailMicroProcessor"));
                pddt.setDetailMicroProcessorCache(rs.getString("detailMicroProcessorCache"));
                pddt.setDetailCpu(rs.getString("detailCpu"));
                pddt.setDetailRam(rs.getString("detailRam"));
                pddt.setDetailGraphic(rs.getString("detailGraphic"));
                pddt.setDetailHdd(rs.getString("detailHdd"));
                pddt.setDetailHardDisk(rs.getString("detailHardDisk"));
                pddt.setDetailIntegrated(rs.getString("detailIntergrated"));
                pddt.setDetailDisplay(rs.getString("detailDisplay"));
                pddt.setDetailNetwork(rs.getString("detailNetwork"));
                pddt.setDetailWireless(rs.getString("detailWireless"));
                pddt.setDetailKeyboard(rs.getString("detailKeyboard"));
                pddt.setDetailPointingDevice(rs.getString("detailPointingDevice"));
                pddt.setDetailExternalPort(rs.getString("detailExternalPort"));
                pddt.setDetailOperatingSystem(rs.getString("detailOperatingSystem"));
                pddt.setDetailBattery(rs.getString("detailBattery"));   
            }
        }
        catch(SQLException ex)
        {
            System.out.println(ex.getMessage());
        }
        helper.close();
        
        return pddt;
    }
}
